package com.corpgovernment.common.apollo;

import com.ctrip.corp.obt.generic.utils.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author lwli
 */
@Component
public class CarApollo extends CommonApollo {

    /**
     * 用车产线
     */
    @Value("${carProductType:}")
    private String carProductType;
    /**
     * 高德账号
     */
    @Value("${GaodeKey:}")
    private String gaodeKey;
    /**
     * 高德密钥
     */
    @Value("${GaodeSecrectKey:}")
    private String gaodeSecrectKey;
    /**
     * 高德地址around查询url
     */
    @Value("${gaodeAroundAddressSearch:}")
    private String gaodeAroundAddressSearch;
    /**
     * 高德地址查询url
     */
    @Value("${gaodeAddressSearch:}")
    private String gaodeAddressSearch;
    /**
     * 高德距离查询url
     */
    @Value("${gaodeDistance:}")
    private String gaodeDistance;
    /**
     * 用车服务商接口名称
     */
    @Value("${carOperatorType:}")
    private String carOperatorType;
    /**
     * 静默授权地址
     */
    @Value("${silentAuthUrlDD:}")
    private String silentAuthUrlDD;
    /**
     * 回调休眠时间
     */
    @Value("${callBackSleepTime:2000}")
    private Long callBackSleepTime;
    /**
     * 创建订单延迟时间
     */
    @Value("${RTNCreateOrderDelay:8000}")
    private Long rTNCreateOrderDelay;
    /**
     * 历史地址大小
     */
    @Value("${HistoryAddressSize:5}")
    private Integer historyAddressSize;
    /**
     * 是否异步初始化订单详情
     */
    @Value("${isInitSyncOrderDetail:true}")
    private boolean isInitSyncOrderDetail;
    /**
     * 司机地址返回时间
     */
    @Value("${driverLocationReturnTime:30}")
    private Long driverLocationReturnTime;

    /**
     * 热门城市ID
     *
     * @return
     */
    public Set<String> getHotCityId() {
        return Optional.ofNullable(getAppProperty("hotCityId", ""))
                .filter(StringUtils::isNotBlank)
                .map(e -> e.split(","))
                .map(e -> Arrays.stream(e).collect(Collectors.toSet()))
                .orElse(new HashSet<>());
    }

    public String getCarProductType() {
        return getAppProperty("carProductType","");
    }

    public String getGaodeKey() {
        return getAppProperty("GaodeKey","");
    }

    public String getGaodeSecrectKey() {
        return getAppProperty("GaodeSecrectKey","");
    }

    public String getGaodeAroundAddressSearch() {
        return getAppProperty("gaodeAroundAddressSearch","");
    }

    public String getGaodeAddressSearch() {
        return getAppProperty("gaodeAddressSearch","");
    }

    public String getGaodeDistance() {
        return getAppProperty("gaodeDistance","");
    }

    public String getCarOperatorType() {
        return getAppProperty("carOperatorType","");
    }

    public String getSilentAuthUrlDD() {
        return getAppProperty("silentAuthUrlDD","");
    }

    public Long getCallBackSleepTime() {
        return Long.parseLong(getAppProperty("callBackSleepTime","2000"));
    }

    public Long getRTNCreateOrderDelay() {
        return Long.parseLong(getAppProperty("RTNCreateOrderDelay","8000"));
    }

    public Integer getHistoryAddressSize() {
        return Integer.parseInt(getAppProperty("HistoryAddressSize","5"));
    }

    public boolean isInitSyncOrderDetail() {
        return Boolean.parseBoolean(getAppProperty("isInitSyncOrderDetail","true"));
    }

    public Long getDriverLocationReturnTime() {
        return Long.parseLong(getAppProperty("driverLocationReturnTime","30"));
    }

    public Boolean getIsBookingRange() {
        return Boolean.valueOf(getAppProperty("isBookingRange","false"));
    }
}
